package com.rome.hotel.data.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.rome.hotel.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rome.hotel.common.annotation.Log;
import com.rome.hotel.common.core.controller.BaseController;
import com.rome.hotel.common.core.domain.AjaxResult;
import com.rome.hotel.common.enums.BusinessType;
import com.rome.hotel.data.domain.HotelFloor;
import com.rome.hotel.data.service.IHotelFloorService;
import com.rome.hotel.common.utils.poi.ExcelUtil;
import com.rome.hotel.common.core.page.TableDataInfo;

/**
 * 楼层Controller
 * 
 * @author rome
 * @date 2023-12-20
 */
@RestController
@Anonymous
@RequestMapping("/data/floor")
public class HotelFloorController extends BaseController
{
    @Autowired
    private IHotelFloorService hotelFloorService;

    /**
     * 查询楼层列表
     */
    @PreAuthorize("@ss.hasPermi('data:floor:list')")
    @GetMapping("/list")
    public TableDataInfo list(HotelFloor hotelFloor)
    {
        startPage();
        List<HotelFloor> list = hotelFloorService.selectHotelFloorList(hotelFloor);
        return getDataTable(list);
    }

    /**
     * 导出楼层列表
     */
    @PreAuthorize("@ss.hasPermi('data:floor:export')")
    @Log(title = "楼层", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotelFloor hotelFloor)
    {
        List<HotelFloor> list = hotelFloorService.selectHotelFloorList(hotelFloor);
        ExcelUtil<HotelFloor> util = new ExcelUtil<HotelFloor>(HotelFloor.class);
        util.exportExcel(response, list, "楼层数据");
    }

    /**
     * 获取楼层详细信息
     */
    @PreAuthorize("@ss.hasPermi('data:floor:query')")
    @GetMapping(value = "/{floorId}")
    public AjaxResult getInfo(@PathVariable("floorId") Long floorId)
    {
        return AjaxResult.success(hotelFloorService.selectHotelFloorByFloorId(floorId));
    }

    /**
     * 新增楼层
     */
    @PreAuthorize("@ss.hasPermi('data:floor:add')")
    @Log(title = "楼层", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotelFloor hotelFloor)
    {
        return toAjax(hotelFloorService.insertHotelFloor(hotelFloor));
    }

    /**
     * 修改楼层
     */
    @PreAuthorize("@ss.hasPermi('data:floor:edit')")
    @Log(title = "楼层", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotelFloor hotelFloor)
    {
        return toAjax(hotelFloorService.updateHotelFloor(hotelFloor));
    }

    /**
     * 删除楼层
     */
    @PreAuthorize("@ss.hasPermi('data:floor:remove')")
    @Log(title = "楼层", businessType = BusinessType.DELETE)
	@DeleteMapping("/{floorIds}")
    public AjaxResult remove(@PathVariable Long[] floorIds)
    {
        return toAjax(hotelFloorService.deleteHotelFloorByFloorIds(floorIds));
    }

    /**
     * 获取所有楼层列表
     */
//    @PreAuthorize("@ss.hasPermi('data:floor:listGetAll')")
    @GetMapping("/listGetAll")
    public AjaxResult listGetAll(HotelFloor hotelFloor)
    {
        List<HotelFloor> list = hotelFloorService.selectHotelFloorList(hotelFloor);
        return AjaxResult.success(list);
    }
}
